package mobile.game.common.net;

import mobile.game.core.Port;
import mobile.game.core.support.TickTimer;
import mobile.game.core.support.log.LogCore;

public class ConnPort extends Port {
	// 每5分钟打印一次连接数
	private TickTimer printNumTimer = new TickTimer(5 * 60000);
	
	public ConnPort(String name) {
		super(name);
	}
	
	public void openConnection(Connection connection) {
		addService(connection);
	}
	
	public void closeConnection(Connection connection) {
		delServiceBySafe(connection.getId());
	}
	
	@Override
	protected void pulseOverride() {
		long now = getTimeCurrent();
		
		// 每10分钟打印一次连接数，有多少下属service，-1就是多少连接
		if(printNumTimer.isPeriod(now)) {
			LogCore.conn.info("{}当前连接数={}", getId(), getServices().size() - 1);
		}
	}

}
